#
# CppUnit.mk
#
# CppUnit distribution definitions.
#

#
# Variables.
#

#
# Define several variables associated with CppUnit.
#
CPPUNIT = cppunit
CPPUNIT_BASE = $(CPPUNIT)-1.12.1
CPPUNIT_DIST_FILE_NAME = $(CPPUNIT_BASE).tar.gz
CPPUNIT_DIST_FILE_PATH = $(DIST_DIR)/$(CPPUNIT_DIST_FILE_NAME)
CPPUNIT_URL = http://downloads.sourceforge.net/cppunit/cppunit-1.12.1.tar.gz

#
# Define the library files produced by CppUnit.
#
CPPUNIT_LIBRARIES = $(addprefix $(LIB_DIR)/,libcppunit.a libcppunit.la $(call shared_library_name,libcppunit) $(call shared_library_name,libcppunit-1.12,1) $(call shared_library_name,libcppunit-1.12,1,0,0))

#
# Directory Variables.
#

#
# CPPUNIT_DIST_DIR
#
# Defines where the CppUnit distribution directory is located.
#
CPPUNIT_DIST_DIR = $(DIST_DIR)/$(CPPUNIT_BASE)

#
# CPPUNIT_INC_DIR
#
# Defines where the CppUnit include directory is located.
#
CPPUNIT_INC_DIR = $(INC_DIR)/$(CPPUNIT)

#
# CPPUNIT_LIB_ARCHIVE
#
# Defines the location and name of the CppUnit library archive.
#
CPPUNIT_LIB_ARCHIVE = $(LIB_DIR)/libcppunit.a

#
# SHARE_DIR
#
# Defines where the share directory is located.
#
SHARE_DIR = share


#
# Canned recipes.
#

#
# Build CppUnit from source.
#
define build_cppunit
	@echo Building CppUnit...
	@cd $(CPPUNIT_DIST_DIR);					     \
		./configure LDFLAGS='-ldl' --prefix=$(DIST_PREFIX) --libdir=$(DIST_LIBDIR); \
		make install clean distclean;				     \
		cd ../../;						     \
		$(call touch_recursive,$(CPPUNIT_INC_DIR));		     \
		$(call touch_recursive,$(LIB_DIR)/libcppunit*.*);	     \
		rm -f $(BIN_DIR)/DllPlugInTester;			     \
		rm -f $(BIN_DIR)/cppunit-config;			     \
		rm -rf $(SHARE_DIR)
endef


#
# Targets.
#

#
# Define the .PHONY CppUnit target.
#
.PHONY: $(CPPUNIT)

#
# Download CppUnit distribution.
#
$(CPPUNIT_DIST_FILE_PATH): | $(DIST_DIR)
	@echo Downloading $(CPPUNIT_DIST_FILE_NAME)...
	@$(call download_file,$(CPPUNIT_DIST_FILE_PATH),$(CPPUNIT_URL))

#
# Extract CppUnit distribution.
#
$(CPPUNIT_DIST_DIR): $(CPPUNIT_DIST_FILE_PATH)
	@echo Extracting $(CPPUNIT_DIST_FILE_NAME)...
	@$(call tar_extract,$(CPPUNIT_DIST_FILE_PATH),$(DIST_DIR))
	@$(call touch_recursive,$(CPPUNIT_DIST_DIR))

#
# CppUnit include directory.
#
$(CPPUNIT_INC_DIR): $(CPPUNIT_DIST_DIR)
	@$(build_cppunit)

#
# CppUnit library files.
#
$(CPPUNIT_LIBRARIES): $(CPPUNIT_DIST_DIR)
	@$(build_cppunit)

#
# CppUnit.
#
$(CPPUNIT): $(CPPUNIT_INC_DIR) $(CPPUNIT_LIBRARIES)
